package edu.nwpu.zya.coreops.modules.monitor.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.models.auth.In;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import edu.nwpu.zya.coreops.modules.monitor.entity.MetricEntity;
import edu.nwpu.zya.coreops.modules.monitor.service.MetricService;
import edu.nwpu.zya.coreops.common.utils.PageUtils;
import edu.nwpu.zya.coreops.common.utils.R;



/**
 * 
 *
 * @author zhouyuang
 * @email 742025491@qq.com
 * @date 2022-04-18 22:48:27
 */
@RestController
@RequestMapping("monitor/metric")
public class MetricController {
    @Autowired
    private MetricService metricService;

    @RequestMapping("/type/{type}")
    public R metricType(@PathVariable("type") Integer type){
        List<MetricEntity> metrics=metricService.list(new QueryWrapper<MetricEntity>().eq("type",type));
        return R.ok().put("metrics",metrics);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("monitor:metric:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = metricService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("monitor:metric:info")
    public R info(@PathVariable("id") Long id){
		MetricEntity metric = metricService.getById(id);

        return R.ok().put("metric", metric);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("monitor:metric:save")
    public R save(@RequestBody MetricEntity metric){
		metricService.save(metric);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("monitor:metric:update")
    public R update(@RequestBody MetricEntity metric){
		metricService.updateById(metric);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("monitor:metric:delete")
    public R delete(@RequestBody Long[] ids){
		metricService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
